package com.yiwenup.leetcode.offer;

import com.yiwenup.leetcode.ListNode;

/**
 * https://leetcode-cn.com/problems/shan-chu-lian-biao-de-jie-dian-lcof/
 */
public class No018 {

    public ListNode deleteNode(ListNode head, int val) {
        if (head.val == val) return head;

        ListNode pre = head;
        ListNode cur = head.next;

        while (cur != null) {
            if (cur.val == val) {
                pre.next = cur.next;
                break;
            } else {
                pre = cur;
                cur = cur.next;
            }
        }

        return head;
    }
}
